# 1.获取appium capabilities
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '9'
desired_caps['deviceName'] = '127.0.0.1:10027'
desired_caps['appPackage'] = 'com.tal.kaoyan'
desired_caps['appActivity'] = 'com.tal.kaoyan.ui.activity.SplashActivity'
desired_caps['noReset'] = False
desired_caps['app'] = r'/home/appium/apps/kaoyan3.1.0.apk'
#toast的配置
desired_caps['automationName'] = 'uiautomator2'
# 中文问题处理
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
# 2.启动app(包含安装过程)
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)

# 3.点击‘取消’按钮
cancel_btn = driver.find_element_by_id('android:id/button2')
cancel_btn.click()

# 4.点击‘跳过’按钮
skip_btn = driver.find_element_by_id('com.tal.kaoyan:id/tv_skip')
skip_btn.click()
# 用户名密码 不能输入～～用例
# 5.点击‘登录’按钮
login_btn = driver.find_element_by_id('com.tal.kaoyan:id/login_login_btn')
login_btn.click()

# toast 定位
try:
    toast = driver.find_element(AppiumBy.XPATH,'//*[@text="邮箱帐户密码不能为空"]')
except:
    print('用例失败!!!')
else:
    print('用例成功！！！')